<template>
  <!-- 运输单位类型查询列表 -->
  <el-dialog :title="isounit.title" :visible.sync="isounit.open" width="700px" append-to-body>
    <!--      <el-table v-loading="loading" :data="isounitList"  @selection-change="handleSelectionChange" id="bootstrap-table">-->
    <el-table v-loading="loading" :data="isounitList" id="bootstrap-table" highlight-current-row @row-click="rowClick">
      <el-table-column label width="35">
        <template slot-scope="scope">
          <el-radio :label="scope.row.unitCode" v-model="unitCode">&nbsp;</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="运输单位类型" prop="unitCode" width="120" />
      <el-table-column label="描述" prop="description" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="因素" prop="presentFactor" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="基本单元" prop="baseUnit" width="100" />
      <el-table-column label="类型" prop="unitType" width="100" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="isounitQueryParams.pageNum"
      :limit.sync="isounitQueryParams.pageSize"
      @pagination="isounitListAll"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="isounitSubmitForm">确 定</el-button>
      <el-button @click="isounitTcancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { listTransport,listIsoUnit,getTransport,delTransport,addAndUpdateTransport,importTemplate,exportTransport,addTransport,updateTransport } from "@/api/erp/transport/transport";
  export default {
    name: 'showList',
    props:{
      isounit:Object
    },
    data(){
      return{
        addOrEit:{
          form:{}
        },
        open:false,
        // 查询参数
        isounitQueryParams: {
          pageNum: 1,
          pageSize: 10,
          unitType: this.isounit.unitType
        },
        total:0,
        loading:false,
        isounitList:[],
        unitCode:undefined,
        selectCode:{
          unitCode:undefined,
          flag:true
        },
        isounits:{
          open:false
        }
      }
    },
    created() {

    },
    watch:{
      'isounit.unitType':function(val) {
            console.info('查询参数')
            console.info(val)
            this.isounitQueryParams.unitType=val
            this.isounitListAll();
      },
      'isounit.open':function(val) {
        console.info('showlList开关')
        console.info(val)
        this.open=val
      }
    },
    methods: {
      /** 显示条件查询列表 */
      showList(value){
        // var str = "";
        // if(value == "Weight"){
        //   str= "(重量)";
        // }else if(value == "Volume"){
        //   str= "(体积)";
        // }
        // this.isounitOpen = true;
        // this.isounitTitle = "选择运输单位类型"+str;
        // this.isounitQueryParams.unitType = value;
        // console.info(this.isounitQueryParams)
        // listIsoUnit(this.isounitQueryParams).then(
        //   response => {
        //     this.isounitList = response.rows;
        //     this.isounitTotal = response.total;
        //     this.loading = false;
        //   }
        // );
      },
      // 条件取消按钮
      isounitTcancel() {
        // this.open = false;
        // this.isounit.open = false;
        this.$emit("update:isounit", this.isounits);
        this.isounitQueryParams.pageNum = 1;
        this.isounitQueryParams.pageSize = 10;
        this.isounitQueryParams.unitType = undefined;
      },
      /** 条件查询列表确定条件 */
      isounitSubmitForm(){
        console.info("-------------")
        console.info(this.selectCode.flag)
        console.info("-------------")
        this.selectCode.unitCode=this.unitCode
        if(this.isounit.type=="header"){
          if(this.isounitQueryParams.unitType == "Weight"){
            this.selectCode.flag=true
          }else if(this.isounitQueryParams.unitType == "Volume"){
            this.selectCode.flag=false
          }
          this.$emit("header",this.selectCode);
          // this.$emit("update:addOrEit", this.addOrEit);
        }else{
          if(this.isounitQueryParams.unitType == "Weight"){
            this.selectCode.flag=true
          }else if(this.isounitQueryParams.unitType == "Volume"){
            this.selectCode.flag=false
          }

          // this.addOrEit.form ={uomForWeight:this.unitCode}
          this.$emit("addOrEdit",this.selectCode);
        }

        this.isounitTcancel()
      },
      //条件查询列表
      getList(){
        // this.loading = true;
        // listTransport(this.queryParams).then(
        //   response => {
        //     this.roleList = response.rows;
        //     this.total = response.total;
        //     this.loading = false;
        //   }
        // );
      },
      /** 搜索按钮操作 */
      isounitListAll() {
        var str = "";
        if(this.isounitQueryParams.unitType == "Weight"){
          str= "(重量)";
        }else if(this.isounitQueryParams.unitType == "Volume"){
          str= "(体积)";
        }
        console.info(this.isounitQueryParams)
        listIsoUnit(this.isounitQueryParams).then(
          response => {
            this.isounitList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      /** 搜索按钮操作 */
      rowClick(row){
        this.unitCode=row.name;
      },
    }
  }
</script>

<style scoped>

</style>
